<html>

<head>
  <meta charset="UTF-8">
  <title>USKD 矿机</title>
  <link rel="stylesheet" href="../static/css/font-awesome.min.css">
  <link rel="stylesheet" href="../static/css/style.css">
  <link rel="stylesheet" href="../static/css/login.css">
  <link rel="stylesheet" href="../static/css/common.css">
  <link rel="stylesheet" href="../static/css/window.css">
  <link rel="stylesheet" href="../static/css/toast.style.css">
</head>

<style>
  body{
    background:url(../static/images/bg.jpg)no-repeat;  
    width:100%;  
    height:100%;  
    background-size:100% 100%;  
    position:absolute;  
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='bg-login.png',sizingMethod='scale'); 
  }
</style>

<body>
  <div class="beforeLogin">
    <div class="navbar">
      <div class="window">
        <div></div>
        <div id="minbt">
          <i class="fa fa-window-minimize" aria-hidden="true"></i>
        </div>
        <div id="maxbt">
          <i class="fa fa-window-maximize" aria-hidden="true"></i>
        </div>
        <div id="closebt">
          <i class="fa fa-times" aria-hidden="true"></i>
        </div>
      </div>
    </div>
    <div id="login">
      <div class="send-info">
        <div>
          <div style="color: #fff;">用户名</div>
          <div>
            <input id="username" style="font-size: 13px; margin-bottom: 15px;" type="text">
          </div>
        </div>
      </div>
      <div class="send-info">
        <div>
          <div style="color: #fff;">密码</div>
          <div>
            <input id="password" style="font-size: 13px; margin-bottom: 15px;" type="password">
          </div>
        </div>
      </div>
      <div class="button">
        <a href="./index.html" style="display:none"></a>
        <button id="submit" type="button">登录</button>
      </div>
    </div>
  </div>
  <!-- <ul class="bg-bubbles">
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul> -->
  <script>
    if (typeof module === 'object') {
      window.module = module;
      module = undefined;
    }
  </script>
  <script type="text/javascript" src="../static/js/jquery-1.11.0.min.js"></script>
  <script src="../static/js/toast.script.js"></script>
  <script>
    if (window.module) module = window.module;
  </script>
  <script>
    var ajaxWebsite = require('../modules/website.js');
    // console.log(ajaxWebsite);
    const ipcRenderer = require('electron').ipcRenderer
    var per
    
    function addToast(title, content, type) {
      $.Toast(title, content, type, {
        stack: true,
        has_icon: true,
        has_close_btn: true,
        fullscreen: false,
        timeout: 2000,
        sticky: false,
        has_progress: true,
        rtl: false,
      });
    }

    // 登录 ajax请求 无session记录
    function login() {
      var username = $('#username').val()
      var password = $('#password').val()

      // console.log(username + "__")

      $.ajax({
        url: ajaxWebsite + 'Home/Ytc/login',
        type: 'POST',
        data: {
          username: username,
          password: password,
        },
        success: function (res) {
          console.log(res)
          var code = res['code']
          if (code == 0 || code == 1) {
            // alert('登录失败')
            addToast('输入错误', '用户名不存在或密码错误', 'error')
          } else if (code == 2 || code == 3) {
            ipcRenderer.send('permission', res)
            window.location.href = './index.html'
          }
        }
      })

    }

    // 按下登录按钮后登录
    $('#submit').click(function () {
      login()
    })

    // 按下回车键后登录
    $('body').keydown(function (event) {
      if (event.keyCode == 13) {
        login()
      }
    })

    // window 最小化 最大化 关闭窗口
    $('#minbt').click(function () {
      ipcRenderer.send('window-min');
    })
    $('#maxbt').click(function () {
      ipcRenderer.send('window-max')
    })
    $('#closebt').click(function () {
      ipcRenderer.send('window-close');
    })

    // 屏蔽ctrl+shift+I 禁止打开开发者工具 
    $("body").bind("keydown", function (e) {
      e = window.event || e;

      if ((event.ctrlKey) && (event.shiftKey) && (event.keyCode == 73)) {
        e.keyCode = 0;
        return false;
      }
    });
  </script>
</body>

</html>